-
Notifications
You must be signed in to change notification settings - Fork 6.9k
feat(plugin): add ToolResult type for structured tool responses #6544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aryasaatvik
wants to merge
5
commits into
anomalyco:dev
Choose a base branch
from
aryasaatvik:fix/plugin-tool-metadata-persistence
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(plugin): add ToolResult type for structured tool responses #6544
aryasaatvik
wants to merge
5
commits into
anomalyco:dev
from
aryasaatvik:fix/plugin-tool-metadata-persistence
+47
−15
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
|
@rekram1-node can you take a look? |
0fa0047 to
d2ef4f0
Compare
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
- Add ToolResult interface to @opencode-ai/plugin
- Update execute signature to Promise<string | ToolResult>
- Enables plugin tools to return {title, metadata, output}
- Add ToolResult interface to @opencode-ai/plugin for structured tool responses - Update execute signature to accept string | ToolResult - Add runtime detection in fromPlugin to preserve title and metadata - Extract Tool.Result interface for clarity in opencode package - Maintain backward compatibility with string-only results
c0c0acf to
f35c3da
Compare
aryasaatvik
added a commit
to aryasaatvik/opencode
that referenced
this pull request
Jan 12, 2026
## Problem
Plugin tools could only return a plain string. This prevented:
- Structured responses with titles, metadata, and attachments
- Real-time streaming updates during long-running operations
- Subagent result propagation (tool counts, progress, etc.)
## Solution
Add ToolResult interface and metadata() method to plugin SDK:
- ToolResult interface: { title, metadata, output, attachments? }
- ctx.metadata(): Emit streaming updates during execution
- Backward compatible: tools can still return plain strings
- Core extraction: Tool.Result interface for unified typing
## Changes
- packages/plugin/src/tool.ts - Add ToolResult interface, metadata() method
- packages/opencode/src/tool/tool.ts - Extract Tool.Result interface
- packages/opencode/src/tool/registry.ts - Handle structured results in fromPlugin
## Usage
```typescript
import { tool, type ToolResult } from "@opencode-ai/plugin"
export default tool({
description: "My tool",
args: { input: z.string() },
async execute(args, ctx): Promise<ToolResult> {
ctx.metadata({ title: "Processing...", metadata: { step: 1 } })
// ... work ...
return {
title: "Done",
metadata: { count: 42 },
output: "Result text"
}
}
})
```
## Related
- Resolves anomalyco#7590
Patchwork-Source: fix/plugin-tool-metadata-persistence
Patchwork-PR: anomalyco#6544
Patchwork-Squashed: 2026-01-12T21:07:21.648Z
aryasaatvik
added a commit
to aryasaatvik/opencode
that referenced
this pull request
Jan 12, 2026
## Problem
Plugin tools could only return a plain string. This prevented:
- Structured responses with titles, metadata, and attachments
- Real-time streaming updates during long-running operations
- Subagent result propagation (tool counts, progress, etc.)
## Solution
Add ToolResult interface and metadata() method to plugin SDK:
- ToolResult interface: { title, metadata, output, attachments? }
- ctx.metadata(): Emit streaming updates during execution
- Backward compatible: tools can still return plain strings
- Core extraction: Tool.Result interface for unified typing
## Changes
- packages/plugin/src/tool.ts - Add ToolResult interface, metadata() method
- packages/opencode/src/tool/tool.ts - Extract Tool.Result interface
- packages/opencode/src/tool/registry.ts - Handle structured results in fromPlugin
## Usage
```typescript
import { tool, type ToolResult } from "@opencode-ai/plugin"
export default tool({
description: "My tool",
args: { input: z.string() },
async execute(args, ctx): Promise<ToolResult> {
ctx.metadata({ title: "Processing...", metadata: { step: 1 } })
// ... work ...
return {
title: "Done",
metadata: { count: 42 },
output: "Result text"
}
}
})
```
## Related
- Resolves anomalyco#7590
Patchwork-Source: fix/plugin-tool-metadata-persistence
Patchwork-PR: anomalyco#6544
Patchwork-Squashed: 2026-01-12T21:07:21.648Z
aryasaatvik
added a commit
to aryasaatvik/opencode
that referenced
this pull request
Jan 12, 2026
## Problem
Plugin tools could only return a plain string. This prevented:
- Structured responses with titles, metadata, and attachments
- Real-time streaming updates during long-running operations
- Subagent result propagation (tool counts, progress, etc.)
## Solution
Add ToolResult interface and metadata() method to plugin SDK:
- ToolResult interface: { title, metadata, output, attachments? }
- ctx.metadata(): Emit streaming updates during execution
- Backward compatible: tools can still return plain strings
- Core extraction: Tool.Result interface for unified typing
## Changes
- packages/plugin/src/tool.ts - Add ToolResult interface, metadata() method
- packages/opencode/src/tool/tool.ts - Extract Tool.Result interface
- packages/opencode/src/tool/registry.ts - Handle structured results in fromPlugin
## Usage
```typescript
import { tool, type ToolResult } from "@opencode-ai/plugin"
export default tool({
description: "My tool",
args: { input: z.string() },
async execute(args, ctx): Promise<ToolResult> {
ctx.metadata({ title: "Processing...", metadata: { step: 1 } })
// ... work ...
return {
title: "Done",
metadata: { count: 42 },
output: "Result text"
}
}
})
```
## Related
- Resolves anomalyco#7590
Patchwork-Source: fix/plugin-tool-metadata-persistence
Patchwork-PR: anomalyco#6544
Patchwork-Squashed: 2026-01-12T21:07:21.648Z
aryasaatvik
added a commit
to aryasaatvik/opencode
that referenced
this pull request
Jan 13, 2026
## Problem
Plugin tools could only return a plain string. This prevented:
- Structured responses with titles, metadata, and attachments
- Real-time streaming updates during long-running operations
- Subagent result propagation (tool counts, progress, etc.)
## Solution
Add ToolResult interface and metadata() method to plugin SDK:
- ToolResult interface: { title, metadata, output, attachments? }
- ctx.metadata(): Emit streaming updates during execution
- Backward compatible: tools can still return plain strings
- Core extraction: Tool.Result interface for unified typing
## Changes
- packages/plugin/src/tool.ts - Add ToolResult interface, metadata() method
- packages/opencode/src/tool/tool.ts - Extract Tool.Result interface
- packages/opencode/src/tool/registry.ts - Handle structured results in fromPlugin
## Usage
```typescript
import { tool, type ToolResult } from "@opencode-ai/plugin"
export default tool({
description: "My tool",
args: { input: z.string() },
async execute(args, ctx): Promise<ToolResult> {
ctx.metadata({ title: "Processing...", metadata: { step: 1 } })
// ... work ...
return {
title: "Done",
metadata: { count: 42 },
output: "Result text"
}
}
})
```
## Related
- Resolves anomalyco#7590
Patchwork-Source: fix/plugin-tool-metadata-persistence
Patchwork-PR: anomalyco#6544
Patchwork-Squashed: 2026-01-12T21:07:21.648Z
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Plugin tools could only return a plain string. This prevented:
Solution
Add ToolResult interface and metadata() method to plugin SDK:
Changes
Usage
Related